#ifndef TCPCLIENT_H
#define TCPCLIENT_H

#include <QObject>
#include <QTcpSocket>

class TcpClient : public QObject
{
Q_OBJECT

public:
    explicit TcpClient(QObject *parent = nullptr);
    ~TcpClient();

    bool connectToServer(const QString &host, quint16 port);

signals:
    void connected();
    void disconnected();
    void error(QAbstractSocket::SocketError error);  // 添加这一行
    void receivedData(QByteArray data);

private slots:
    void onConnected();
    void onDisconnected();
    void onError(QAbstractSocket::SocketError error);
    void onReadyRead();

private:
    QTcpSocket *m_socket;
};

#endif // TCPCLIENT_H
